<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017\10\14 0014
 * Time: 17:17
 */
namespace Home\Controller;
use Home\Controller\CommonController;

class OrderController extends CommonController{
    public function index(){
        $orderinfo = M("order")->order("payment asc")->select();
        $ordercount =M("order")->count();
        $this->assign("ordercount",$ordercount);
        $this->assign("orderinfo",$orderinfo);
        $this->display();
    }
    public function add(){
        if(IS_POST){
            $post= I("post.");
            $post['ord_date']=$post['edit_date']=date("Y-m-d",time());
            $orderadd= M("order")->data($post)->add();
            if($orderadd){
                echo true;
            }else{
                echo false;
            }
        }else{
            $alipay = M("alipay")->select();
            $customer = M("customer")->select();
            $designer = M("designer")->select();
            $qq = M("qq")->select();
            $supplier = M("supplier")->select();

            $this->assign("alipay", $alipay);
            $this->assign("customer", $customer);
            $this->assign("designer", $designer);
            $this->assign("qq", $qq);
            $this->assign("supplier", $supplier);

            $this->display();
        }

    }
    public function edit(){
        if(IS_POST){
            $post=I("post.");
            $post['edit_date']=date("Y-m-d",time());
            $bol =M("order")->data($post)->where("id={$_GET['id']}")->save();
            if($bol){
                echo true;
            }else{
                echo false;
            }
        }else{
            $alipay = M("alipay")->select();
            $customer = M("customer")->select();
            $designer = M("designer")->select();
            $qq = M("qq")->select();
            $supplier = M("supplier")->select();
            $order =M("order")->where("id={$_GET['id']}")->select();

            $this->assign("alipay", $alipay);
            $this->assign("customer", $customer);
            $this->assign("designer", $designer);
            $this->assign("qq", $qq);
            $this->assign("supplier", $supplier);
            $this->assign("order",$order);
            $this->display();
        }
    }
    public function del(){
        $id=I("get.id");
        $del = M("order")->where("id={$id}")->delete();
        if($del){
            echo true;
        }else{
            echo false;
        }
    }
    public function batch_del(){
        $post=I("post.id");
        if($post){
            foreach($post as $id){
                $bol=M("order")->where("id={$id}")->delete();
                if($bol){
                    $arr["id"][] =$id;
                }
            }
            echo json_encode($arr);
        }else{
            echo false;
        }
    }
    public function search(){

        $data =M("order")->where($_POST)->select();
        if($data){
            echo json_encode($data);
        }else{
            echo false;
        }
    }
    public function _empty(){
        $this->display("没有这个方法");
    }
}